package com.server.llh.llhserverwork.activity.food;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.bean.ProductBean;

import java.util.List;


/**
 * Created by ZTF on 2017-06-14.
 */

public class FoodOrderInfoActivity extends Activity {
    ImageButton leftBtn;
    TextView titlebarText;
    ListView llh_infomation_list;
    List<ProductBean> product=null;
    private static final String TAG="FoodOrderInfo";

    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getlayout());
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        leftBtn= (ImageButton) findViewById(R.id.left_btn);
        titlebarText= (TextView) findViewById(R.id.titlebar_text);
        llh_infomation_list= (ListView) findViewById(R.id.llh_infomation_list);
        titlebarText.setText("餐品详情");
        leftBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        product=SubFoodOrderInfoActivity.product;
        if (product!=null&&product.size()>0){
            Log.d(TAG,"supplierInfoBeen=="+product.size());
            OrderFoodAdapter foodOrderAdapter=new OrderFoodAdapter(getApplicationContext(),product);
            llh_infomation_list.setAdapter(foodOrderAdapter);
        }

    }


    class OrderFoodAdapter extends BaseAdapter {
        Context context;
        private List<ProductBean> listFood;
        ProductBean orderFood;
        public OrderFoodAdapter(Context context,List<ProductBean> listFood) {
            this.listFood = listFood;
            this.context= context;
        }

        @Override
        public int getCount() {
            if (listFood == null || listFood.size() == 0) {
                return 0;
            }
            return listFood.size();
        }

        @Override
        public Object getItem(int position) {
            return listFood.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder1 = new  ViewHolder();

            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(
                        R.layout.order_food_type, parent, false);
                holder1.order_food_name = (TextView) convertView
                        .findViewById(R.id.order_food_name);
                holder1.order_food_price = (TextView) convertView
                        .findViewById(R.id.order_food_price);
                holder1.order_food_num = (TextView) convertView
                        .findViewById(R.id.order_food_num);
                convertView.setTag(holder1);
            } else {
                holder1 = (ViewHolder) convertView.getTag();
            }
            orderFood=listFood.get(position);
            holder1.order_food_name.setText(orderFood.getProName()
                    + "(" + orderFood.getCateName()+ ")");
            holder1.order_food_price.setText("￥"
                    + orderFood.getProPrice());
            holder1.order_food_num.setText("x"
                    + orderFood.getProNum());

            return convertView;
        }

        class ViewHolder {
            TextView order_food_name, order_food_price, order_food_num ;
        }
    }


    protected int getlayout() {
        return R.layout.llh_infomation_list;
    }

}
